<?php
require_once(dirname(__FILE__)."/../core/safeParam.php");
class module
{
  function DeletePizza($vars)
  {
    global $database;
    $database->delete('item_pizza', "id = " . $vars['id'] . "");
    header("Location: ../admin/index.php?edit=specials&updated=1&id=" . $vars['pid'] . "&action=edit");
  }
  function EditPizza($vars, $files)
  {
    global $database;
    $d['name']          = $vars['name'];
    $d['topping_price'] = $vars['topping_price'];
    $d['toppings']      = $vars['toppings'];
    $d['base']          = $vars['base'];
    $d['max_toppings']  = $vars['max_toppings'];
    $d['discount']      = $vars['discount'];
    $d['free_topping']  = $vars['free_topping'];
    $d['meat_toppings'] = $vars['meat_toppings'];
    $d['topoff']        = $vars['topoff'];
    $d['sauce']         = $vars['sauce'];
    $d['pop']           = $vars['pop'];
    $d['pos']           = $vars['pos'];
    if ($vars['sides'][0] == "") {
      $sides[0] = 0;
    } //$vars['sides'][0] == ""
    else {
      $sides[0] = 1;
    }
    if ($vars['sides'][1] == "") {
      $sides[1] = 0;
    } //$vars['sides'][1] == ""
    else {
      $sides[1] = 1;
    }
    if ($vars['sides'][2] == "") {
      $sides[2] = 0;
    } //$vars['sides'][2] == ""
    else {
      $sides[2] = 1;
    }
    if ($vars['sides'][3] == "") {
      $sides[3] = 0;
    } //$vars['sides'][3] == ""
    else {
      $sides[3] = 1;
    }
    $d['sides'] = serialize($sides);
    $database->update_array('item_pizza', $d, "id = " . $vars['id'] . "");
    header("Location: ../admin/index.php?edit=specials&updated=1&id=" . $vars['pid'] . "&action=edit");
  }
  function AddPizza($vars, $files)
  {
    global $database;
    $d['name']          = $vars['name'];
    $d['topping_price'] = $vars['topping_price'];
    $d['toppings']      = $vars['toppings'];
    $d['base']          = $vars['base'];
    $d['max_toppings']  = $vars['max_toppings'];
    $d['discount']      = $vars['discount'];
    $d['free_topping']  = $vars['free_topping'];
    $d['meat_toppings'] = $vars['meat_toppings'];
    $d['topoff']        = $vars['topoff'];
    $d['sauce']         = $vars['sauce'];
    $d['pid']           = $vars['pid'];
    $d['rid']           = $vars['rid'];
    $d['pos']           = $vars['pos'];
    $d['pop']           = $vars['pop'];
    if ($vars['sides'][0] == "") {
      $sides[0] = 0;
    } //$vars['sides'][0] == ""
    else {
      $sides[0] = 1;
    }
    if ($vars['sides'][1] == "") {
      $sides[1] = 0;
    } //$vars['sides'][1] == ""
    else {
      $sides[1] = 1;
    }
    if ($vars['sides'][2] == "") {
      $sides[2] = 0;
    } //$vars['sides'][2] == ""
    else {
      $sides[2] = 1;
    }
    if ($vars['sides'][3] == "") {
      $sides[3] = 0;
    } //$vars['sides'][3] == ""
    else {
      $sides[3] = 1;
    }
    $d['sides'] = serialize($sides);
    $database->insert_array('item_pizza', $d);
    header("Location: ../admin/index.php?edit=specials&updated=1&id=" . $vars['pid'] . "&action=edit");
  }
  function Add($vars, $files)
  {
    global $database;
    $d['name']          = $vars['name'];
    $d['price']         = $vars['price'];
    $d['rid']           = $vars['rid'];
    $d['description']   = $vars['description'];
    $d['discount']      = $vars['discount'];
    $d['free_toppings'] = $vars['free_toppings'];
    $d['toppings_fee']  = $vars['toppings_fee'];
    if ($files['image']['size'] != 0) {
      $image       = uploadImage($files, '800', '800', '../UserFiles/Image/product_photos/', 'image');
      $image_thumb = uploadImage($files, '500', '500', '../UserFiles/Image/product_photos/', 'image');
      $d['image']  = $image;
    } //$files['image']['size'] != 0
    $database->insert_array('item_special', $d);
    header("Location: ../admin/index.php?edit=specials&updated=1");
  }
  function Edit($vars, $files)
  {
    global $database;
    $d['name']          = $vars['name'];
    $d['discount']      = $vars['discount'];
    $d['price']         = $vars['price'];
    $d['description']   = $vars['description'];
    $d['free_toppings'] = $vars['free_toppings'];
    $d['toppings_fee']  = $vars['toppings_fee'];
    if ($files['image']['size'] != 0) {
      $image       = uploadImage($files, '800', '800', '../UserFiles/Image/product_photos/', 'image');
      $image_thumb = uploadImage($files, '500', '500', '../UserFiles/Image/product_photos/', 'image');
      $d['image']  = $image;
    } //$files['image']['size'] != 0
    $database->update_array('item_special', $d, "id = " . $vars['id'] . "");
    header("Location: ../admin/index.php?edit=specials&updated=1");
  }
  function Delete($vars)
  {
    global $database;
    $database->delete('item_special', "id = " . $vars['id'] . "");
    header("Location: ../admin/index.php?edit=specials&updated=1");
  }
}
?>
